package siam.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 * 
 * {@link DirectionLabel} extends {@link JLabel} represent the JLabel to select {@link Force}
 * @author Motassim Saad
 * @See {@link Force}
 */
@SuppressWarnings("serial")
public class DirectionLabel extends JLabel {

	/**
	 * {@link Force} 
	 */
	private Force force;
	/**
	 * Image in Label which represent force direction
	 */
	private Image img ;
	/**
	 * Constructor {@link DirectionLabem} 
	 * @param {@link Force} 
	 */
	public DirectionLabel(Force force) {
		super();
		this.force=force;
		 img = force.getImg();
		this.setMaximumSize(new Dimension(10, 10));
		this.setPreferredSize(new Dimension(20, 20));
		this.addMouseListener(new MouseDirectionListener(force));

	}
	
	public Force getForce() {
		return force;
	}
	
	/**
	 * Activate the label , ie border became yellow
	 */
	public void activate(){
		this.setBackground(Color.yellow);
		this.setBorder(BorderFactory.createLineBorder(Color.yellow));
		repaint();
	}
	
	/**
	 * Desactivate the label 
	 */
	public void desactivate(){
		this.setBackground(Color.DARK_GRAY);
		this.setBorder(BorderFactory.createBevelBorder(HORIZONTAL));
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		ImageIcon icon = new ImageIcon(img.getScaledInstance((int)1.5*this.getWidth(),(int)1.5* this.getHeight(), Image.SCALE_FAST));
		this.setIcon(icon);
	}
	
	
	
}
